<template>
	<div>
		<div>
			<MkCard>
				<BaseSearchForm 
					v-model:search-param="searchParam"
					@goBack="emit('goto-edit')"
					@search="search"
					@add="handleAdd"
					:isShowBack="false" 
					:isShowHistoryTitle="false"
					:isShowAdd="true"
				/>
			</MkCard>
			<MkCard>
				<MkTable height="600px" :data="filteredList" @row-dblclick="rowDbClick">
					<el-table-column label="ID" prop="id" />
					<el-table-column label="检验套餐分组名称" prop="name" />
					<el-table-column label="互扫分组" prop="group" />
					<el-table-column label="互扫默认套餐" prop="defaultPackage" />
					<el-table-column label="自编号前缀" prop="prefix" width="150px" />
					<el-table-column label="是否启用自定自编号" prop="autoNumber" />
					<el-table-column label="未检验能否直接审核" prop="directAudit" />
					<el-table-column label="排序" prop="sort" />
					<MkColumnIsEnabled prop="isEnabled"/>
				</MkTable>
			</MkCard>
		</div>
		<Edit  ref="editRef" @returnData="returnData"/>
		<!-- <EditDialog ref="editDialogRef" /> -->
	</div>
</template>
<script lang="ts" setup>
import Edit from './components/Edit.vue';
import { ref,onMounted } from 'vue';
const editRef = ref();
// import EditDialog from './components/EditDialog.vue';
// const editDialogRef = ref();
/**
 * 增加检验套餐分组
 */
//定义检索变量
const searchParam = reactive({
	keyword: undefined,
	startCreationTime: undefined,
	endCreationTime: undefined,
});
interface jilei {
  id: number;
  name: string;
	group: string;
  defaultPackage: string;
  prefix: string;
  autoNumber: string;
  directAudit: string;
	sort: string;
	isEnabled:boolean;
}
//假数据
const List =  ref<jilei[]>([{
	id: 1,
	name: '张三',
	group: '分组1',
	defaultPackage: '套餐A',
	prefix: 'A',
	autoNumber: '11',
	directAudit: '能',
	sort: '1',
	isEnabled:false
},{
	id: 2,
	name: '李四',
	group: '分组2',
	defaultPackage: '套餐B',
	prefix: 'A',
	autoNumber: '11',
	directAudit: '能',
	sort: '2',
	isEnabled:true
},{
	id: 3,
	name: '王五',
	group: '分组1',
	defaultPackage: '套餐A',
	prefix: 'A',
	autoNumber: '11',
	directAudit: '能',
	sort: '3',
	isEnabled:false
}]);

// 用于存储过滤后的结果
const filteredList = ref<jilei[]>([]);
//检索
const search = () => {
  const keyword = searchParam.keyword;

  // 如果没有关键字，返回全部数据
  if (!keyword) {
    filteredList.value = List.value;
    return;
  }
  filteredList.value = List.value.filter(item => {
    return (
      item.name.toLowerCase().includes(keyword) ||
      item.group.toLowerCase().includes(keyword) ||
      item.defaultPackage.toLowerCase().includes(keyword)
    );
  });
};	
const emit = defineEmits(['goto-edit'])
const handleAdd = () => {
	editRef.value.openDrawerFn();
	//editDialogRef.value.showDialog();
};
const rowDbClick = (row: any) => {
	editRef.value.openDrawerFn();
  editRef.value.DataAssignment(row);
}
//修改页回显数据
const returnData = (data: any)=>{
	let index = List.value.findIndex(t => t.id == data.value.id)
	if(index != -1){
		filteredList.value[index] = data.value
	}
}
onMounted(() => {
  search();
});
defineOptions({
	name: 'InpItemGroup',
});
</script>
